/**
 * Created by @daniel_hxxh on 2017/8/16.
 */
CHANGE_PWD = {};

CHANGE_PWD.__INIT__ = function(){
	mainView.router.load({
		url:'src/my_center/accent_setting/change_pwd.html'
	})
};


var yanzheng = false;
var yanzheng1 = false;
var yanzheng2 = false;

//旧密码验证
CHANGE_PWD.old_password = function(e){
	if($(e).val() != '') {
        yanzheng = true;//密码
    }
}


//密码验证
CHANGE_PWD.password1 = function(){
	yanzheng1 = true;
    if($("input[name='password2']").val()){
        if($("input[name='password1']").val() != $("input[name='password2']").val()) {
           my_tips_("两次输入的密码不一致,请重新输入！");
            yanzheng1 = false;
            return ;
        }else {
            yanzheng1 = true;//密码
            yanzheng2 = true;//密码
        }
    }
}

CHANGE_PWD.password2 = function(){
	if($("input[name='password1']").val() != $("input[name='password2']").val()) {
        my_tips_("两次输入的密码不一致,请重新输入！");
        yanzheng2 = false;
        return ;
    }else {
        yanzheng1 = true;//密码
    	yanzheng2 = true;//密码
    }
}

CHANGE_PWD.change_pwd_submit = function(){
    if(!yanzheng1 || !yanzheng2){
        my_tips_("两次输入的密码不一致,请重新输入！");
        return;
    }
    var pwd = $("input[name='password1']").val();
    var url = url_('index/User/up_password');
    var data = {
        old_password: $("input[name='old_password']").val(),
        password: pwd
    }
    var success = function (res) {
        if(res.code == 0){
            my_tips_('修改成功',function(){
            	go_href_('#/accent_setting');
            });
//			Storage_.set('p_',encrypt(pwd));
        }else {
            my_tips_(res.msg);
        }
    }
    request_(url,data,success);
}

CHANGE_PWD.change_pay_pwd = function(code, pwd){
	console.log(code+' '+pwd)
	CHANGE_PWD.pay_pwd1 = pwd;
	my_tips_('再次确认密码',function(){
		YUE.__INIT__(CHANGE_PWD.change_pay_pwd2);
	})
}

CHANGE_PWD.change_pay_pwd2 = function (code, pwd) {
	CHANGE_PWD.pay_pwd2 = pwd;
	if (CHANGE_PWD.pay_pwd1 == CHANGE_PWD.pay_pwd2) {
		var url = url_('index/User/up_pay_password');
		var data = {'password':pwd};
		var success = function(d){
			if (d.code == 0) {
				my_tips_(d.msg,function(){
					go_href_('#/accent_setting');
				})
			} else{
				my_tips_(d.msg);
			}
		}
		request_(url,data,success)
	} else{
		my_tips_('两次密码输入不一致！',function(){
			go_href_('#/accent_setting');
		})
	}
}